package com.easygo.controller;

import com.easygo.api.GoodsSearchClient;
import com.easygo.utils.PageUtils;
import com.xuexi.easygo.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@Scope("prototype")
public class GoodsServiceController {

    @Autowired
    ElasticsearchTemplate elasticsearchTemplate;

    @Autowired
    GoodsSearchClient goodsSearchClient;

    @RequestMapping("get_Goods")
    public String goods_search(@RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,
                               @RequestParam(value = "pageSize",defaultValue = "12") Integer pageSize,
                               @RequestParam(value = "keyWords",defaultValue = "") String keyWords,
                               Model model){

        PageUtils<Goods> pageUtils = goodsSearchClient.goods_search(pageIndex, pageSize, keyWords);
        model.addAttribute("pageUtils",pageUtils);
        System.out.println("搜索结果是："+pageUtils);
        model.addAttribute("keyWords",keyWords);
        return "categoryList";
    }
}
